]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
shell/global: Watch for switcheroo-control appearing
authorBastien Nocera <hadess@hadess.net>
Tue, 28 Apr 2020 15:24:06 +0000 (17:24 +0200)
committerFlorian Müllner <fmuellner@gnome.org>
Mon, 4 May 2020 14:22:03 +0000 (16:22 +0200)
Rather than staticly expecting switcheroo-control to already be running
on the system, wait for it appearing and disappearing.

https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1226

src/shell-global.c

index 6ad7a6673aab038c10fe32af00d628cb9afaa4bd..0488c3c4413597debdcbc17f89e8511352067ced 100644 (file)
@@ -299,6 +299,35 @@ shell_global_get_property(GObject         *object,
     }
 }
 
+static void
+switcheroo_appeared_cb (GDBusConnection *connection,
+                        const char     *name,
+                        const char     *name_owner,
+                        gpointer        user_data)
+{
+  ShellGlobal *global = user_data;
+
+  g_debug ("switcheroo-control appeared");
+  shell_net_hadess_switcheroo_control_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
+                                                         G_DBUS_PROXY_FLAGS_NONE,
+                                                         "net.hadess.SwitcherooControl",
+                                                         "/net/hadess/SwitcherooControl",
+                                                         global->switcheroo_cancellable,
+                                                         switcheroo_control_ready_cb,
+                                                         global);
+}
+
+static void
+switcheroo_vanished_cb (GDBusConnection *connection,
+                        const char      *name,
+                        gpointer         user_data)
+{
+  ShellGlobal *global = user_data;
+
+  g_debug ("switcheroo-control vanished");
+  g_clear_object (&global->switcheroo_control);
+}
+
 static void
 shell_global_init (ShellGlobal *global)
 {
@@ -394,13 +423,13 @@ shell_global_init (ShellGlobal *global)
                                             g_object_unref, g_object_unref);
 
   global->switcheroo_cancellable = g_cancellable_new ();
-  shell_net_hadess_switcheroo_control_proxy_new_for_bus (G_BUS_TYPE_SYSTEM,
-                                                         G_DBUS_PROXY_FLAGS_NONE,
-                                                         "net.hadess.SwitcherooControl",
-                                                         "/net/hadess/SwitcherooControl",
-                                                         global->switcheroo_cancellable,
-                                                         switcheroo_control_ready_cb,
-                                                         global);
+  g_bus_watch_name (G_BUS_TYPE_SYSTEM,
+                    "net.hadess.SwitcherooControl",
+                    G_BUS_NAME_WATCHER_FLAGS_NONE,
+                    switcheroo_appeared_cb,
+                    switcheroo_vanished_cb,
+                    global,
+                    NULL);
 }
 
 static void